package com.teradyne.phoenix.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.teradyne.phoenix.client.factory.AppFactory;
import com.teradyne.phoenix.client.mvp.AppActivityMapper;
import com.teradyne.phoenix.client.mvp.AppPlaceHistoryMapper;
import com.teradyne.phoenix.client.places.UserPlace;
import com.teradyne.phoenix.client.views.AppLayout;
import com.teradyne.phoenix.client.views.AppLayoutImpl;
import com.teradyne.phoenix.client.views.ContentArea;

public class PhoenixAdmin implements EntryPoint {

//	private static PhoenixAdminUiBinder uiBinder = GWT
//			.create(PhoenixAdminUiBinder.class);
//
//	interface PhoenixAdminUiBinder extends
//			UiBinder<DockLayoutPanel, PhoenixAdmin> {
//	}

	private Place defaultPlace = new UserPlace();

	private PlaceController placeController;


	@SuppressWarnings("deprecation")
	@Override
	public void onModuleLoad() {
//		DockLayoutPanel appMain = uiBinder.createAndBindUi(this);
		
		AppFactory appFactory = GWT.create(AppFactory.class);
		EventBus eventBus = appFactory.getEventBus();
		placeController = appFactory.getPlaceController();
		
		AppLayout appLayout = new AppLayoutImpl(appFactory);
		
		ActivityMapper activityMapper = new AppActivityMapper(appFactory);
		ActivityManager activityManager = new ActivityManager(activityMapper,
				eventBus);
		activityManager.setDisplay((AcceptsOneWidget) appLayout.getContentPanel());

		AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
		historyHandler.register(placeController, eventBus, defaultPlace);
		
		RootLayoutPanel.get().add(appLayout.getMainPanel());
		new AppController(appFactory);
		historyHandler.handleCurrentHistory();
		

		GWT.log("User agent: " + Window.Navigator.getUserAgent());
	}

}
